<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> 
	<head>
		<meta charset="utf-8">
		<title>岗位列表</title>
		
		<!-- 引入layui支持 -->
		<script type="text/javascript" th:src="@{/js/jquery.min.js}" ></script>
		<script type="text/javascript" th:src="@{/js/afquery.js}" ></script>
		<script type="text/javascript" th:src="@{/layui/layui.all.js}" ></script>
		<link rel="stylesheet" th:href="@{/layui/css/layui.css}" />
		
		<style>
			.titleaa:hover{
				color: #23a1ff;
			}
			.title{
				font-weight: 700;
				line-height: 28px;
				font-size: 20px;
				width: 505px;
				overflow: hidden;
				white-space: nowrap;
			}
			.content{
				height: 100%; 
				min-height: 80px; 
				margin: 25px 0px; 
				padding: 10px;
				
				box-shadow: -1px 3px 8px #1e9fff;
			}
			.header{
				padding: 15px;
				border: 1px solid #009688;
				display: inline-block; 
				box-shadow: 0px 3px 7px #009688;
			}
			
		</style>
		
	</head>
	<body>
	<div class="layui-container">
		
		<!-- 岗位搜索框 -->
		<div class="header">
			搜索岗位：
			<div class="layui-inline">
				<input class="layui-input uname" placeholder="请输入岗位名称" autocomplete="off">
			</div>
			<button class="layui-btn" onclick="my.Search()">搜索</button>
		</div>
		
		<!-- 整个内容区 -->
		<div class="layui-row">
			<div class="layui-col-xs12 layui-col-sm12 layui-col-md9">	<!-- 第一大块 -->
				<!-- 岗位显示区 -->
				<div class="layui-row content" th:each=" row : ${postList}">			
					<!-- 第一块10 -->
					<div class="layui-col-xs12 layui-col-sm12 layui-col-md9">		
						<a class="titleaa" th:href="@{/u/postfin(postId=${row.id})}">
							<div class="title">
								<label>[[${row.title}]]</label>
								<label style="color: #FF0000;" th:text="| ${row.wagesmin}-${row.wagesmax}元 |"> </label>
								<span th:if="${row.state==0}" class="layui-badge layui-bg-blue">在招</span>
								<span th:if="${row.state==1}" class="layui-badge">停招</span>
							</div>
						</a>
						<span>地址：[[${row.workaddress}]]</span>
						<div style="color: #23A1FF;">
						  招[[${row.hiring}]]人 | [[${row.experience}]] | [[${row.academicDegree}]]
						</div>
					</div>
					
					<!-- 第二块2 -->
					<div class="layui-col-xs12 layui-col-sm12 layui-col-md3">		
						<div>发布日期：[[${row.timerelease}]]</div>
						<div>最近更新：[[${row.timeupdate}]]</div>
						<shiro:hasPermission name="gy:r:find">
							<div th:rowid='${row.id}'>
								<button type="button" class="layui-btn layui-btn-normal" onclick="my.userSetFlags(this, 'updateY', 'reload')">在招</button>
								<button type="button" class="layui-btn layui-btn-danger" onclick="my.userSetFlags(this, 'updateN', 'reload')">停招</button>
							</div>
						</shiro:hasPermission>
					</div>
					
				</div>
				<!-- 分页区 -->
				<div>
					<div class="page-index-bar" 
						style="text-align: right;"></div>
				</div>
			</div>
			
			<!-- 广告区 -->
			<div class="layui-col-xs12 layui-col-sm12 layui-col-md3">	<!-- 第二大块 -->
				<div th:replace=" ~{popularize::header}"></div>
			</div>
		
		</div>
		
	</div>
	</body>
	<script>
		var my = {};
		var serviceUri = '[[${url}]]' ; // 当前查询的URI
				
		// 在招、停招切换
		my.userSetFlags = function(dom, cmd, action) {
			var promptText = $(dom).text(); // == "在招"
			if (!confirm("确认操作：" + promptText + '?')) return; // 浏览器自带对话框的使用,点击确定返回true,否则false

			var rowid = Number($(dom).parent().attr('rowid')); // 取得本帖子的ID
			var req = {};
			req.postId = rowid; // 帖子ID
			req.cmd = cmd; // 'updateY/updateN'
			Af.rest('[[@{/enterprise/updateState.do}]]', req, function(data) {
				// if(action == 'back') location.href = '[[@{/message/list}]]' ;	//返回还不够,还要刷新一下
				if (action == 'reload') location.reload();
			})
		}
		
		// 点击搜索按钮
		my.Search = function()
		{
			var filter = $('.uname').val().trim();		// 取得搜索的值
			location.href = my.pageUrl(1, filter);
		}
		// 搜用户url指定
		my.pageUrl = function(pageNumber, filter)
		{
			// 因为后台的请求接口是GET请求,所以把请求附件在URL 后面
			var url = '[[${url}]]';
			url += '?pageNumber=' + pageNumber;
			
			if(filter.length > 0 && filter != null)
			{
				// url += '&filter=' + encodeURIComponent(filter);	// 把汉字变成URL编码
				url += '&filter=' + encodeURIComponent(filter);	// 把汉字变成URL编码
			}
			return url;
		}
		
		// 分页
		var pageCount = [[${pageCount}]];
		var pageNumber = [[${pageNumber}]];
		// 初始化执行: 分页显示
		my.initPage = function(){
			var str = "";			
			var skipped = false;
			for(var i=1; i<=pageCount; i++)
			{
				// 如果页面数过多，则添加一个省略号
				if(i< pageNumber - 2 && i >= 2)
				{
					if(!skipped ) str += "...";
					skipped = true;
					continue;
				}
				if(i> pageNumber + 2 && i <= pageCount - 1)
				{
					if(!skipped ) str += "...";
					skipped = true;
					continue;
				}
				skipped = false;
				
				// 当前页码： 以高亮显示
				if(i == pageNumber)
					str += "<lable class='layui-btn'> ##1 </lable>".replace(/##1/g, i);
				else
					str += "<a class='layui-btn layui-btn-primary' href='##0?pageNumber=##1'> ##1 </a>"
						.replace(/##0/g, serviceUri)
						.replace(/##1/g, i);
						
				$('.page-index-bar').html(str);	
			}
		}(); // 立即执行 my.initPage()
	</script>
	
</html>
